<template>
  <div>
    <h1>商家列表</h1>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="userId" label="序号" />
      <el-table-column prop="userName" label="名称" />
      <el-table-column prop="userMobile" label="手机号" />
      <el-table-column prop="createTime" label="创建时间" />
    </el-table>
    <div style="margin-top: 20px">
      <el-pagination
        v-model:current-page="pageFrom.pageNum"
        v-model:page-size="pageFrom.pageSize"
        :page-sizes="[2, 4, 6, 8]"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { getShopUser } from "@/api/api";
import { pa } from "element-plus/es/locales.mjs";
const tableData = ref([]);
const total = ref(0);
const pageFrom = ref({
  pageNum: 1,
  pageSize: 2,
});
const loadUserList = () => {
  getShopUser(pageFrom.value).then((res) => {
    tableData.value = res.data.data.records;
    total.value = res.data.data.total;
  });
};

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  pageFrom.value.pageSize = val;
  loadUserList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  pageFrom.value.pageSize = val;
  loadUserList();
};
onMounted(() => {
  loadUserList();
});
</script>
